{% extends 'base_main.html' %}

{% block Meta %}
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
{% endblock %}
{% block content %}
<section class="rt_wrap content mCustomScrollbar">
    <div class="rt_content">
        <div class="page_title">
            <h2 class="fl">商品列表</h2>
            <a href="{% url 'goods:goods_detail' %}" class="fr top_rt_btn add_icon">添加商品</a>
        </div>
        <table class="table">
            <tr>
                <th>缩略图</th>
                <th>产品名称</th>
                <th>商品类型</th>
                <th>货号</th>
                <th>市场单价</th>
                <th>本店单价</th>
                <th>库存</th>
                <th>详情</th>
                <th>操作</th>
            </tr>
            {% for good in goods %}
                <tr>
                    <td class="center"><img src="/media/{{ good.goods_front_image }}" width="50" height="50" alt="" /></td>
                    <td class="center">{{ good.name }}</td>
                    <td class="center">
                        {% for type in types %}
                            {% ifequal type.0 good.category_id  %}
                                {{ type.1 }}
                            {% endifequal %}
                        {% endfor %}
                    </td>
                    <td class="center">{{ good.goods_sn }}</td>
                    <td class="center"><strong class="rmb_icon">{{ good.market_price }}</strong></td>
                    <td class="center"><strong class="rmb_icon">{{ good.shop_price }}</strong></td>
                    <td class="center">{{ good.goods_nums }}</td>
                    <td class="center">
                        <a href="{% url 'goods:goods_desc' good.id %}">{{ good.goods_brief }}</a>
                    </td>
                    <td class="center">
                        <a href="{% url 'goods:goods_alter' good.id %}" title="编辑" class="link_icon">&#101;</a>
{#                        <a href="{% url 'goods:goods_delete' good.id %}" title="删除" class="link_icon">&#100;</a>#}
                        <a onclick ='good_del({{ good.id }});' title="删除" class="link_icon">&#100;</a>

                    </td>
                </tr>
            {% endfor %}
        {% csrf_token %}
            <script>
                function good_del(id) {
                    var csrf = $('input[name="csrfmiddlewaretoken"]').val()
                    $.ajax({
                        url:'/goods/goods_delete/'+id+'/',
                        {# #}
                        dataType:'json',
                        type:"POST",
                        headers:{'X-CSRFToken':csrf},
                        success:function (data) {
                            {# 这个data值就是接收的JsonResponse数据 #}
                            if(data.code == '200'){
                                location.reload()
                            }
                        },
                        error:function (data) {
                            alert('删除失败')
                        }
                    })

                }
            </script>
        </table>
        <aside class="paging">
            <a {% if goods.has_previous %} href = "{% url 'goods:goods_list' goods.previous_page_number %}"{% endif %}>上一页</a>

            <a href="{% url 'goods:goods_list' 1 %}">第一页</a>
                    {% for page in range_pages %}
                        <a href="{% url 'goods:goods_list' page %}"> {{ page }}</a>
                    {% endfor %}


            <a href="{% url 'goods:goods_list' paginator_total %}">最后一页</a>
        </aside>
    </div>
</section>

{% endblock %}